<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once 'connectDb.php';


$name = addslashes($_SESSION['fb_name']);
$id = addslashes($_SESSION['fb_id']);
$title = addslashes($_POST['title']);
$msg = addslashes($_POST['invitation_message']);
$guests_id = $_POST['guests_ids'];




$time = time();
$now = (int) (date('Y', $time) . date('m', $time) . date('j', $time));

$c_date = $now;
$g_date = $_POST['goal_date'];
$c_qty = 0;
$g_qty = $_POST['goal_quantity'];
$status = 'A';

$query = "INSERT INTO event VALUES('','$name','$id','$title','$msg','$c_date','$g_date','$c_qty','$g_qty','$status')";

$insert = mysql_query($query);
$evid = mysql_insert_id();


if (isset($guests_id) && $guests_id != '' && $guests_id != ' ') {
  $guests_id = rtrim($guests_id, ",");
  $ids = explode(",", $guests_id);
  $totalGuests = count($ids);
  echo "ids " .$ids ;
  for ($i = 0; $i < $totalGuests; $i++) {
    $uname = explode("---", $ids[$i]);

    if ($uname[0] != 'undefined') {
      $query2 = "INSERT INTO guest(fb_user_id,name) VALUES('$uname[0]','$uname[1]')";
      $insert2 = mysql_query($query2);

      $guestid = mysql_insert_id($conexion);
      $query3 = "INSERT INTO event_has_guest(event_id,guest_id) VALUES('$evid','$guestid')";
      $insert3 = mysql_query($query3);      
    }
  }
}


//while ($r_g = mysql_fetch_array($get_pos)) {
//
//}
?>
